package com.biglead.demo.rabbit.order.delay;
import com.biglead.demo.pojo.Order;
import com.biglead.demo.pojo.OrderMessage;
import com.biglead.demo.pojo.SecKillMessage;
import com.biglead.demo.service.OrderService;
import com.biglead.demo.utils.JsonUtils;
import com.biglead.demo.vo.OrderVo;
import lombok.extern.log4j.Log4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Log4j
@RabbitListener(queues = OrderDelayedMessageConfig.DIRECT_QUEUE)//监听队列名称
public class OrderDelayedMQReciever {

    @Autowired
    private OrderService orderService;

    @RabbitHandler
    public void process(String message){
       log.info("DelayedMQReciever接收到的消息是："+ message);
        OrderMessage orderMessage = JsonUtils.toObj(message, OrderMessage.class);
        Long orderId = orderMessage.getOrderId();
        //查询订单是否是未支付
        Order order = orderService.getOrderDetail(orderId);
        Integer status = order.getStatus();
        if(status==0){
            //未支付 取消订单
            order.setStatus(6);
            //更新数据库订单状态
            orderService.updateOrderById(order);
            //更新redis 订单状态
            //更新ES 中订单状态
            //恢复商品库存
            //更新redis中的商品库存
        }

    }
}
